package com.example.administrator.darkslog;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.andova.component.log.externs.FilePicker;

import java.io.BufferedOutputStream;
import java.io.OutputStream;

import static com.example.administrator.darkslog.LoggerApplication.LOGGER;

public class MainActivity extends AppCompatActivity {
    private boolean terminate = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Thread(new Runnable() {
            private int counter = 0;

            @Override
            public void run() {
                while (!terminate) {
                    ++counter;
                    LOGGER.info("the counter message is -> " + counter + ", >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
                    try {
                        Thread.sleep(50L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    @Override
    protected void onResume() {
        super.onResume();
        terminate = false;
    }

    @Override
    protected void onPause() {
        super.onPause();
        terminate = true;
    }

    public void writeToFile() throws Exception {
        FilePicker filePicker = new FilePicker();
        OutputStream out = new BufferedOutputStream(filePicker.getOutputStream("/storage/emulated/0/logs/log_2017_11_13.txt", true), 100);
        byte[] data = "test/TEXT/TEST--------1".getBytes();
        out.write(data);
        out.close();
    }

    public void printLog(View view) {
        LOGGER.info(((EditText) findViewById(R.id.et_content)).getText().toString());
    }
}
